//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.come.good;

import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;
import org.come.Frame.ZhuFrame;
import org.come.bean.PrivateData;
import org.come.bean.Skill;
import org.come.entity.Goodstable;
import org.come.mouslisten.GoodsMouslisten;
import org.come.until.AnalysisString;
import org.come.until.SendRoleAndRolesummingUntil;
import org.come.until.UserMessUntil;

public class Consumptions {
	public Consumptions() {
	}

	public static void Consumption(Goodstable goodstable, String value) {
		long[] xiaohao = AnalysisString.xiaohao(value);
		if (xiaohao[4] != 0L) {
			int use = goodstable.getUsetime();
			skillProficiency(goodstable, (int)xiaohao[4]);
			if (use != goodstable.getUsetime()) {
				goodstable.setUsetime(use);
			} else {
				goodstable.goodxh(1);
				GoodsMouslisten.gooduse(goodstable, 1);
				SendRoleAndRolesummingUntil.sendRole(RoleData.getRoleData().getPrivateData());
			}

		}
	}

	public static boolean skillProficiency(Goodstable goodPlace, int addsld) {
		PrivateData data = RoleData.getRoleData().getPrivateData();
		int sld = AnalysisString.shuliandu(ImageMixDeal.userimg.getRoleShow().getGrade());
		String[] vs = data.getSkill("S");
		if (vs == null) {
			ZhuFrame.getZhuJpanel().addPrompt2("你还未学习技能");
			goodPlace.setUsetime(goodPlace.getUsetime() + 1);
			return false;
		} else {
			boolean a = false;

			for(int i = 0; i < vs.length; ++i) {
				String[] vs2 = vs[i].split("_");
				double usersld = Double.parseDouble(vs2[1]);
				if ((double)sld > usersld) {
					Skill skill = UserMessUntil.getSkillId(vs2[0]);
					if (skill != null) {
						if ((double)sld < usersld + (double)addsld) {
							addsld = (int)((double)sld - usersld);
						}

						usersld += (double)addsld;
						ZhuFrame.getZhuJpanel().addPrompt2("你的" + skill.getSkillname() + "获得" + addsld + "熟练度");
						a = true;
						vs[i] = vs2[1] + "_" + (int)usersld;
						StringBuffer buffer = new StringBuffer();

						for(int j = 0; j < vs.length; ++j) {
							if (buffer.length() != 0) {
								buffer.append("#");
							}

							buffer.append(vs[j]);
						}

						data.setSkills("S", buffer.toString());
						SendRoleAndRolesummingUntil.sendRole(data);
						break;
					}
				}
			}

			if (!a) {
				ZhuFrame.getZhuJpanel().addPrompt2("技能熟练度已满!");
				goodPlace.setUsetime(goodPlace.getUsetime() + 1);
			}

			return false;
		}
	}

	//新版战斗自动显示
	public static boolean addSkillProficiency(final String SkillName, final int addsld) {
		final PrivateData data = RoleData.getRoleData().getPrivateData();
		final int sld = AnalysisString.shuliandu(ImageMixDeal.userimg.getRoleShow().getGrade().intValue());
		final String[] vs = data.getSkill("S");
		if (vs == null) {
			return false;
		}
		else {
			boolean a = false;
			int i = 0;
			while (i < vs.length) {
				final String[] vs2 = vs[i].split("_");
				if(vs2.length>1){
					double usersld = Double.parseDouble(vs2[1]);
					if (usersld < (double)sld) {
						final Skill skill = UserMessUntil.getSkillId(vs2[0]);
						if (skill != null) {
							if (skill.getSkillname().equals(SkillName)) {
								usersld += (double)addsld;
								a = true;
								vs[i] = vs2[0] + "_" + (int)usersld;
								final StringBuffer buffer = new StringBuffer();
								int j = 0;
								while (j < vs.length) {
									if (buffer.length() != 0) {
										buffer.append("#");
									}
									buffer.append(vs[j]);
									++j;
								}
								data.setSkills("S", buffer.toString());
								SendRoleAndRolesummingUntil.sendRole(data);
								break;
							}
						}
					}
				}

				++i;
			}
			return false;
		}
	}
}
